home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3s / scanf.z / scanf
Encoding:
Text File  |  2002-10-03  |  20.4 KB  |  329 lines

  1.  
  2.  
  3.  
  4. ssssccccaaaannnnffff((((3333SSSS))))                                                            ssssccccaaaannnnffff((((3333SSSS))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      _ssss_cccc_aaaa_nnnn_ffff, _ffff_ssss_cccc_aaaa_nnnn_ffff, _ssss_ssss_cccc_aaaa_nnnn_ffff - convert formatted input
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      _####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ssss_tttt_dddd_iiii_oooo_...._hhhh_>>>>
  13.      _iiii_nnnn_tttt _ssss_cccc_aaaa_nnnn_ffff_((((_cccc_oooo_nnnn_ssss_tttt _cccc_hhhh_aaaa_rrrr _****_ffff_oooo_rrrr_mmmm_aaaa_tttt_,,,, _...._...._...._))))_;;;;
  14.      _iiii_nnnn_tttt _ffff_ssss_cccc_aaaa_nnnn_ffff_((((_FFFF_IIII_LLLL_EEEE _****_ssss_tttt_rrrr_mmmm_,,,, _cccc_oooo_nnnn_ssss_tttt _cccc_hhhh_aaaa_rrrr _****_ffff_oooo_rrrr_mmmm_aaaa_tttt_,,,, _...._...._...._))))_;;;;
  15.      _iiii_nnnn_tttt _ssss_ssss_cccc_aaaa_nnnn_ffff_((((_cccc_oooo_nnnn_ssss_tttt _cccc_hhhh_aaaa_rrrr _****_ssss_,,,, _cccc_oooo_nnnn_ssss_tttt _cccc_hhhh_aaaa_rrrr _****_ffff_oooo_rrrr_mmmm_aaaa_tttt_,,,, _...._...._...._))))_;;;;
  16.  
  17. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  18.      _ssss_cccc_aaaa_nnnn_ffff reads from the standard input stream, _ssss_tttt_dddd_iiii_nnnn.
  19.  
  20.      _ffff_ssss_cccc_aaaa_nnnn_ffff reads from the stream _s_t_r_m.
  21.  
  22.      _ssss_ssss_cccc_aaaa_nnnn_ffff reads from the character string _s.
  23.  
  24.      Each function reads characters, interprets them according to a format,
  25.      and stores the results in its arguments.  Each expects, as arguments, a
  26.      control string, _f_o_r_m_a_t, described below and a set of pointer arguments
  27.      indicating where the converted input should be stored.  If there are
  28.      insufficient arguments for the format, the behavior is undefined.  If the
  29.      format is exhausted while arguments remain, the excess arguments are
  30.      simply ignored.
  31.  
  32.      The control string usually contains conversion specifications, which are
  33.      used to direct interpretation of input sequences.  The control string may
  34.      contain:
  35.  
  36.           1.  White-space characters (blanks, tabs, newlines, or form-feeds)
  37.               that, except in two cases described below, cause input to be
  38.               read up to the next non-white-space character.
  39.  
  40.           2.  An ordinary character (not _%%%%) that must match the next character
  41.               of the input stream.
  42.  
  43.           3.  Conversion specifications consisting of the character _%%%% or the
  44.               character sequence _%%%%_d_i_g_i_t_s_$$$$, an optional assignment suppression
  45.               character _****, a decimal digit string that specifies an optional
  46.               numerical maximum field width, an optional letter _llll (ell), _LLLL, or
  47.               _hhhh indicating the size of the receiving object, and a conversion
  48.               code.  The conversion specifiers _dddd, _iiii, and _nnnn should be preceded
  49.               by _hhhh if the corresponding argument is a pointer to _ssss_hhhh_oooo_rrrr_tttt _iiii_nnnn_tttt
  50.               rather than a pointer to _iiii_nnnn_tttt, by _llll if it is a pointer to _llll_oooo_nnnn_gggg
  51.               _iiii_nnnn_tttt or by _llll_llll if it is a pointer to a _llll_oooo_nnnn_gggg _llll_oooo_nnnn_gggg _iiii_nnnn_tttt.  Similarly,
  52.               the conversion specifiers _oooo, _uuuu, and _xxxx should be preceded by _hhhh if
  53.               the corresponding argument is a pointer to _uuuu_nnnn_ssss_iiii_gggg_nnnn_eeee_dddd _ssss_hhhh_oooo_rrrr_tttt _iiii_nnnn_tttt
  54.               rather than a pointer to _uuuu_nnnn_ssss_iiii_gggg_nnnn_eeee_dddd _iiii_nnnn_tttt, by _llll if it is a pointer
  55.               to _uuuu_nnnn_ssss_iiii_gggg_nnnn_eeee_dddd _llll_oooo_nnnn_gggg _iiii_nnnn_tttt, or by _llll_llll if it is a pointer to a _uuuu_nnnn_ssss_iiii_gggg_nnnn_eeee_dddd
  56.               _llll_oooo_nnnn_gggg _llll_oooo_nnnn_gggg _iiii_nnnn_tttt.  The conversion specifiers _eeee, _ffff, and _gggg should be
  57.               preceded by _llll if the corresponding argument is a pointer to
  58.               _dddd_oooo_uuuu_bbbb_llll_eeee rather than a pointer to _ffff_llll_oooo_aaaa_tttt.  The conversion
  59.  
  60.  
  61.                                                                         PPPPaaaaggggeeee 1111
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. ssssccccaaaannnnffff((((3333SSSS))))                                                            ssssccccaaaannnnffff((((3333SSSS))))
  69.  
  70.  
  71.  
  72.               specifiers _eeee, _ffff, and _gggg should be preceded by _LLLL if the
  73.               corresponding argument is a pointer to _llll_oooo_nnnn_gggg _dddd_oooo_uuuu_bbbb_llll_eeee rather than a
  74.               pointer to _ffff_llll_oooo_aaaa_tttt.  Finally, the conversion specifiers _cccc and _ssss
  75.               should be preceded by _llll if the corresponding argument points to
  76.               an array of type _wwww_cccc_hhhh_aaaa_rrrr______tttt.  This will result in the same behavior
  77.               as using the _CCCC and _SSSS specifiers (described below).  The _hhhh, _llll,
  78.               _llll_llll, or _LLLL modifier is ignored with any other conversion
  79.               specifier.
  80.  
  81.      A conversion specification directs the conversion of the next input
  82.      field; the result is placed in the variable pointed to by the
  83.      corresponding argument unless assignment suppression was indicated by the
  84.      character _****.  The suppression of assignment provides a way of describing
  85.      an input field that is to be skipped.  An input field is defined as a
  86.      string of non-space characters; it extends to the next inappropriate
  87.      character or until the maximum  field width, if one is specified, is
  88.      exhausted.  For all descriptors except the character _[[[[ and the character
  89.      _cccc, white space leading an input field is ignored.
  90.  
  91.      Conversions can be applied to the _n_t_h argument in the argument list,
  92.      rather than to the next unused argument.  In this case, the conversion
  93.      character _%%%% (see above) is replaced by the sequence _%%%%_d_i_g_i_t_s_$$$$ where _d_i_g_i_t_s
  94.      is a decimal integer _n, giving the position of the argument in the
  95.      argument list.  The first such argument, _%%%%_1111_$$$$, immediately follows _f_o_r_m_a_t.
  96.      The control string can contain either form of a conversion specification,
  97.      i.e., _%%%% or _%%%%_d_i_g_i_t_s_$$$$, although the two forms cannot be mixed within a
  98.      single control string.
  99.  
  100.      The conversion code indicates the interpretation of the input field; the
  101.      corresponding pointer argument must usually be of a restricted type.  For
  102.      a suppressed field, no pointer argument is given.  The following
  103.      conversion codes are valid:
  104.  
  105.      _%%%%    A single _%%%% is expected in the input at this point; no assignment is
  106.           done.
  107.  
  108.      _dddd    Matches an optionally signed decimal integer, whose format is the
  109.           same as expected for the subject sequence of the _ssss_tttt_rrrr_tttt_oooo_llll function
  110.           with the value 10 for the _b_a_s_e argument.  The corresponding argument
  111.           should be a pointer to integer.
  112.  
  113.      _uuuu    Matches an optionally signed decimal integer, whose format is the
  114.           same as expected for the subject sequence of the _ssss_tttt_rrrr_tttt_oooo_uuuu_llll function
  115.           with the value 10 for the _b_a_s_e argument.  The corresponding argument
  116.           should be a pointer to unsigned integer.
  117.  
  118.      _oooo    Matches an optionally signed octal integer, whose format is the same
  119.           as expected for the subject sequence of the _ssss_tttt_rrrr_tttt_oooo_uuuu_llll function with
  120.           the value 8 for the _b_a_s_e argument.  The corresponding argument
  121.           should be a pointer to unsigned integer.
  122.  
  123.  
  124.  
  125.  
  126.  
  127.                                                                         PPPPaaaaggggeeee 2222
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134. ssssccccaaaannnnffff((((3333SSSS))))                                                            ssssccccaaaannnnffff((((3333SSSS))))
  135.  
  136.  
  137.  
  138.      _xxxx    Matches an optionally signed hexadecimal integer, whose format is
  139.           the same as expected for the subject sequence of the _ssss_tttt_rrrr_tttt_oooo_uuuu_llll
  140.           function with the value 16 for the _b_a_s_e argument.  The corresponding
  141.           argument should be a pointer to unsigned integer.
  142.  
  143.      _iiii    Matches an optionally signed integer, whose format is the same as
  144.           expected for the subject sequence of the _ssss_tttt_rrrr_tttt_oooo_llll function with the
  145.           value 0 for the _b_a_s_e argument.  The corresponding argument should be
  146.           a pointer to integer.
  147.  
  148.      _nnnn    No input is consumed.  The corresponding argument should be a
  149.           pointer to integer into which is to be written the number of
  150.           characters read from the input stream so far by the call to the
  151.           function.  Execution of a _%%%%_nnnn directive does not increment the
  152.           assignment count returned at the completion of execution of the
  153.           function.
  154.  
  155.      _eeee,_ffff,_gggg
  156.           Matches an optionally signed floating point number, whose format is
  157.           the same as expected for the subject string of the _ssss_tttt_rrrr_tttt_oooo_dddd function.
  158.           The corresponding argument should be a pointer to floating.
  159.  
  160.      _ssss    A character string is expected; the corresponding argument should be
  161.           a character pointer pointing to an array of characters large enough
  162.           to accept the string and a terminating _\\\\_0000, which will be added
  163.           automatically.  The input field is terminated by a white-space
  164.           character.
  165.  
  166.      _SSSS    Same as _ssss except that the corresponding argument should be a _wwww_cccc_hhhh_aaaa_rrrr______tttt
  167.           pointer pointing to an array of _wwww_cccc_hhhh_aaaa_rrrr______tttt large enough to accept the
  168.           string and a terminating _\\\\_0000, which will be added automatically.
  169.  
  170.      _cccc    Matches a sequence of characters of the number specified by the
  171.           field width (1 if no field width is present in the directive).  The
  172.           corresponding argument should be a pointer to the initial character
  173.           of an array large enough to accept the sequence.  No null character
  174.           is added.  The normal skip over white space is suppressed.
  175.  
  176.      _CCCC    Same as _cccc except that the corresponding argument should be a pointer
  177.           to the initial character of an array of type _wwww_cccc_hhhh_aaaa_rrrr______tttt large enough to
  178.           accept the sequence.
  179.  
  180.      _[[[[    Matches a nonempty sequence of characters from a set of expected
  181.           characters (the _s_c_a_n_s_e_t).  The corresponding argument should be a
  182.           pointer to the initial character of an array large enough to accept
  183.           the sequence and a terminating null character, which will be added
  184.           automatically.  The conversion specifier includes all subsequent
  185.           characters in the _f_o_r_m_a_t string, up to and including the matching
  186.           right bracket (_]]]]).  The characters between the brackets (the
  187.           _s_c_a_n_l_i_s_t) comprise the scanset, unless the character after the left
  188.           bracket is a circumflex (_^^^^), in which case the scanset contains all
  189.           characters that do not appear in the scanlist between the circumflex
  190.  
  191.  
  192.  
  193.                                                                         PPPPaaaaggggeeee 3333
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200. ssssccccaaaannnnffff((((3333SSSS))))                                                            ssssccccaaaannnnffff((((3333SSSS))))
  201.  
  202.  
  203.  
  204.           and the right bracket.  If the conversion specifier begins with _[[[[_]]]]
  205.           or _[[[[_^^^^_]]]], the right bracket character is in the scanlist and the next
  206.           right bracket character is the matching right bracket that ends the
  207.           specification; otherwise the first right bracket character is the
  208.           one that ends the specification.
  209.  
  210.           A range of characters in the scanset may be represented by the
  211.           construct _f_i_r_s_t _---- _l_a_s_t; thus _[[[[_0000_1111_2222_3333_4444_5555_6666_7777_8888_9999_]]]] may be expressed _[[[[_0000_----_9999_]]]].
  212.           Using this convention, _f_i_r_s_t must be lexically less than or equal to
  213.           _l_a_s_t, or else the dash will stand for itself. The character _---- will
  214.           also stand for itself whenever it is the first or the last character
  215.           in the scanlist.  To include the right bracket as an element of the
  216.           scanset, it must appear as the first character (possibly preceded by
  217.           a circumflex) of the scanlist and in this case it will not be
  218.           syntactically interpreted as the closing bracket.  At least one
  219.           character must match for this conversion to be considered
  220.           successful.
  221.  
  222.      _pppp    Matches an implementation-defined set of sequences, which should be
  223.           the same as the set of sequences that may be produced by the _%%%%_pppp
  224.           conversion of the _pppp_rrrr_iiii_nnnn_tttt_ffff function. The corresponding argument should
  225.           be a pointer to _vvvv_oooo_iiii_dddd. The interpretation of the input item is
  226.           implementation-defined. If the input item is a value converted
  227.           earlier during the same program execution, the pointer that results
  228.           shall compare equal to that value; otherwise, the behavior of the _%%%%_pppp
  229.           conversion is undefined.
  230.  
  231.      If an invalid conversion character follows the _%%%%, the results of the
  232.      operation may not be predictable.
  233.  
  234.      The conversion specifiers _EEEE, _GGGG, and _XXXX are also valid and behave the same
  235.      as _eeee, _gggg, and _xxxx, respectively.
  236.  
  237.      Each function allows for detection of a language-dependent decimal-point
  238.      character in the input string.  The decimal-point character is defined by
  239.      the program's locale (category _LLLL_CCCC______NNNN_UUUU_MMMM_EEEE_RRRR_IIII_CCCC).  In the _""""_CCCC_"""" locale, or in a
  240.      locale where the decimal-point character is not defined, the decimal-
  241.      point character defaults to a period (_....).
  242.  
  243.      The _ssss_cccc_aaaa_nnnn_ffff conversion terminates at end-of-file, at the end of the control
  244.      string, or when an input character conflicts with the control string.
  245.  
  246.      If end-of-file is encountered during input, conversion is terminated.  If
  247.      end-of-file occurs before any characters matching the current directive
  248.      have been read (other than leading white space, where permitted),
  249.      execution of the current directive terminates with an input failure;
  250.      otherwise, unless execution of the current directive is terminated with a
  251.      matching failure, execution of the following directive (if any) is
  252.      terminated with an input failure.
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.                                                                         PPPPaaaaggggeeee 4444
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266. ssssccccaaaannnnffff((((3333SSSS))))                                                            ssssccccaaaannnnffff((((3333SSSS))))
  267.  
  268.  
  269.  
  270.      If conversion terminates on a conflicting input character, the offending
  271.      input character is left unread in the input stream.  Trailing white space
  272.      (including newline characters) is left unread unless matched by a
  273.      directive.  The success of literal matches and suppressed assignments is
  274.      not directly determinable other than via the _%%%%_nnnn directive.
  275.  
  276. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  277.      The call to the function _ssss_cccc_aaaa_nnnn_ffff:
  278.  
  279.           _iiii_nnnn_tttt _iiii_,,,, _nnnn_;;;; _ffff_llll_oooo_aaaa_tttt _xxxx_;;;; _cccc_hhhh_aaaa_rrrr _nnnn_aaaa_mmmm_eeee_[[[[_5555_0000_]]]]_;;;;
  280.           _nnnn _==== _ssss_cccc_aaaa_nnnn_ffff _((((_""""_%%%%_dddd_%%%%_ffff_%%%%_ssss_""""_,,,, _&&&&_iiii_,,,, _&&&&_xxxx_,,,, _nnnn_aaaa_mmmm_eeee_))))_;;;;
  281.  
  282.      with the input line:
  283.  
  284.           _2222_5555 _5555_4444_...._3333_2222_EEEE_----_1111 _tttt_hhhh_oooo_mmmm_pppp_ssss_oooo_nnnn
  285.  
  286.      will assign to _nnnn the value _3333, to _iiii the value _2222_5555, to _xxxx the value _5555_...._4444_3333_2222,
  287.      and _nnnn_aaaa_mmmm_eeee will contain _tttt_hhhh_oooo_mmmm_pppp_ssss_oooo_nnnn_\\\\_0000.
  288.  
  289.      The call to the function _ssss_cccc_aaaa_nnnn_ffff:
  290.  
  291.           _iiii_nnnn_tttt _iiii_;;;; _ffff_llll_oooo_aaaa_tttt _xxxx_;;;; _cccc_hhhh_aaaa_rrrr _nnnn_aaaa_mmmm_eeee_[[[[_5555_0000_]]]]_;;;;
  292.           _((((_vvvv_oooo_iiii_dddd_)))) _ssss_cccc_aaaa_nnnn_ffff _((((_""""_%%%%_2222_dddd_%%%%_ffff_%%%%_****_dddd _%%%%_[[[[_0000_----_9999_]]]]_""""_,,,, _&&&&_iiii_,,,, _&&&&_xxxx_,,,, _nnnn_aaaa_mmmm_eeee_))))_;;;;
  293.  
  294.      with the input line:
  295.  
  296.           _5555_6666_7777_8888_9999 _0000_1111_2222_3333 _5555_6666_aaaa_7777_2222
  297.  
  298.      will assign _5555_6666 to _iiii, _7777_8888_9999_...._0000 to _xxxx, skip _0000_1111_2222_3333, and place the characters _5555_6666_\\\\_0000
  299.      in _nnnn_aaaa_mmmm_eeee.  The next character read from _ssss_tttt_dddd_iiii_nnnn will be _aaaa.
  300.  
  301. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  302.      _cccc_cccc(1), _ssss_tttt_rrrr_tttt_oooo_dddd(3C), _ssss_tttt_rrrr_tttt_oooo_llll(3C), _pppp_rrrr_iiii_nnnn_tttt_ffff(3S).
  303.  
  304. DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  305.      These routines return the number of successfully matched and assigned
  306.      input items; this number can be zero in the event of an early matching
  307.      failure between an input character and the control string.  If the input
  308.      ends before the first matching failure or conversion, _EEEE_OOOO_FFFF is returned.
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.                                                                         PPPPaaaaggggeeee 5555
  326.  
  327.  
  328.  
  329.